// 流操作
const http = require('http');
const fs = require('fs');
const path = require('path');

//----读取流的方式读取大文件
const server = http.createServer(function(req,res){
    let method = req.method;
    let fileName = path.resolve(__dirname, 'data.txt');
    if(method=='GET'){
        fs.readFile(fileName, function(err, data){
            res.end(data);
        });
    }

    // let stream = fs.createReadStream(fileName);
    //直接数据发送到 res 流行
    // stream.pipe(res);
});

server.listen(8000);




